package com.example.pythondemo.model;

import com.example.pythondemo.utils.IntKit;
import lombok.Data;

import java.util.List;

@Data
public class FileIndex {
    private String fileName;    //文件名
    private Integer index = 0;  //当前索引
    private Integer nextIndex = 0;  //历史索引
    private String oldUrl;  //上一章网络路径

    public int add(){
        nextIndex = index;  //将当前索引赋值给历史索引
        index++;    //获取此刻新的索引
        return index;
    }

    public void index(int num,String oldUrl){
        if (index == 0){    //当前索引为0时，传入索引为起始索引
            index = num;
            this.oldUrl = oldUrl;
        }else if (num == index + 1){ //当前索引为历史索引+1时，视为连续正常读写
            nextIndex = index;
            index ++;
            this.oldUrl = oldUrl;
        }else { //否则视为文件缺失
            nextIndex = index;
            index = num;//记录当前索引
            List<Integer> lost = IntKit.getLost(nextIndex, index);
            System.out.println(lost + "章缺失,你可以点击此处前往网页阅读：" + this.oldUrl);
            this.oldUrl = oldUrl;
        }
    }
}
